<template>
  <div class="app-container">
    <!-- 底部导航栏 -->
    <van-tabbar v-model="activeTab" class="custom-tabbar" active-color="#FED844">
      <!-- 明细 -->
      <van-tabbar-item 
      name="detail" 
      icon="notes-o" 
      @click="handleTabChange('detail')">
      明细</van-tabbar-item>
      <!-- 资产 -->
      <van-tabbar-item
      name="asset"
      icon="balance-list-o" 
      @click="handleTabChange('asset')">资产</van-tabbar-item>
      <!-- 记账 -->
      <van-tabbar-item name="add" @click="handleTabChange('add')">
        <template #icon >
          <div class="tabbar-center">
            <span style="font-size: 30px;">+</span>
          </div>
          <div class="tabbar-text">
            <span>记账</span>
          </div>
        </template>
      </van-tabbar-item>
      <!-- 图表页面 -->
      <van-tabbar-item 
      name="chart" 
      icon="chart-trending-o" 
      @click="handleTabChange('chart')">图表</van-tabbar-item>
      <!-- 我的页面 -->
      <van-tabbar-item 
      icon="user-circle-o" 
      name="mine" 
      @click="handleTabChange('mine')">我的</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script setup>
import { ref, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';  // 新增路由相关导入

const route = useRoute();
const router = useRouter();
const activeTab = ref(route.name || 'detail');


// 监听路由变化更新底部导航状态
watch(route, () => {
  if (route.name) {
    activeTab.value = route.name;
  }
});

// 处理底部导航点击
const handleTabChange = (tab) => {
  if (tab === 'add') {
    // 新增：跳转到记账页面
    router.push({ name: 'tallyForm' });
    return;
  }  
  router.push({ name: tab });
};

</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "PingFang SC", "Helvetica Neue", Arial, sans-serif;
}

.van-tabbar-item {
  font-size: 12px;
  color: #6F6F6F; /* vant默认文字颜色 */
}
/* 新增：调整图标大小 */
:deep(.van-tabbar-item__icon) {
  font-size: 24px; /* 默认20px，调大到24px */
}


.app-container {
  max-width: 500px;
  margin: 0 auto;
  background-color: #fff;
  display: flex;
  flex-direction: column;
  color: #333;
}

.header {
  background: linear-gradient(135deg, #113c9f, #e2ca6b);
  color: white;
  padding: 20px 16px;
  text-align: center;
}

.header h1 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 10px;
}

.balance-section {
  display: flex;
  justify-content: space-around;
  margin: 20px 0;
}

.balance-item {
  text-align: center;
}

.balance-label {
  font-size: 14px;
  opacity: 0.8;
  margin-bottom: 5px;
}

.balance-amount {
  font-size: 20px;
  font-weight: bold;
}

.month-selector {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
}

.month-selector span {
  margin: 0 10px;
  font-size: 16px;
  font-weight: 500;
}

.page-content {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
}

.no-data {
  text-align: center;
  color: #999;
  margin-top: 50px;
}

.no-data-icon {
  font-size: 60px;
  margin-bottom: 20px;
  color: #e0e0e0;
}

.custom-tabbar {
  height: 55px;
  /* 上部横线 */
  border-top: 2px solid #f0f0f0;
}

.tabbar-center {
  /* 边框 */
  border:#ffffff 6px solid;
  /* 阴影 */
  box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.1);
  /* 浮于最上方 */
  position: relative;
  bottom: 8px;  /* 上移8px */
  background: #FED844;
  border-radius: 50%;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgb(0, 0, 0);
}

.tabbar-center .van-icon {
  font-size: 24px;
}

.page-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  color: #333;
}

.budget-card,
.assets-card {
  background: white;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-value {
  font-size: 28px;
  font-weight: bold;
  color: #FED844;
  margin: 10px 0;
}

.card-subtitle {
  font-size: 14px;
  color: #999;
}

.cashback-section {
  background: linear-gradient(135deg, #ff9800, #f57c00);
  border-radius: 12px;
  padding: 20px;
  color: white;
  text-align: center;
  margin-bottom: 16px;
}

.cashback-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 10px;
}

.cashback-amount {
  font-size: 32px;
  font-weight: bold;
  margin-bottom: 10px;
}

.more-section {
  background: white;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.more-item {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #f0f0f0;
}

.more-item:last-child {
  border-bottom: none;
}

.more-icon {
  width: 24px;
  height: 26px;
  background: #FED844;
  border-radius: 6px;
  margin-right: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 14px;
}

.more-text {
  flex: 1;
  font-size: 16px;
}

.more-arrow {
  color: #ccc;
}
.tabbar-text {
  padding-left: 18px;
  padding-bottom: 30px;
  font-size: 12px;
  color: #6A6A6A;
}

</style>